package com.credit.management.system.model;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;
@Component
public class Page<T> {
	private Integer pageNum;//当前页码
	private Integer totalPage;//总页数
	private Integer pageSize;//页面显示条数
	private Integer startIndex;
	private Integer total;//总条数
	private List<T> list;//返回数据
	private Map<String,Object> params;
//	public Page(Integer pageNum,Integer pageSize){
//		if(pageNum!=null){			
//			this.pageNum=pageNum;			
//		}else{
//			this.pageNum=1;
//		}
//		if (pageSize!=null) {
//			this.pageSize = pageSize;
//		}else{
//			this.pageSize=5;
//		}
//		this.startIndex=(pageNum-1)*pageSize;
//	}
	public Page(Integer startIndex,Integer pageSize) {
		this.startIndex=startIndex;
		this.pageSize=pageSize;
	}
	public Page() {
//		if(pageNum!=null&&pageSize!=null){
//			this.startIndex=(pageNum-1)*pageSize;
//		}else{
//			this.startIndex=1;
//		}
	}
	public Integer getPageNum() {
		return pageNum;
	}
	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}
	public Integer getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}
	public Integer getPageSize() {
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Integer getTotal() {
		return total;
	}
	public void setTotal(Integer total) {
		this.total = total;
		this.totalPage=this.total%this.pageSize==0?this.total/this.pageSize:(this.total/this.pageSize)+1;
	}
	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public Map<String, Object> getParams() {
		return params;
	}
	public void setParams(Map<String, Object> params) {
		this.params = params;
	}
	public Integer getStartIndex() {
		return startIndex;
	}
	public void setStartIndex(Integer startIndex) {		
//		if (startIndex==null) {
//			if (pageNum != null && pageSize != null) {
//				this.startIndex = (pageNum - 1) * pageSize;
//			} 
//		}else{
			this.startIndex = startIndex;
//		}
	}
	@Override
	public String toString() {
		return "Page [pageNum=" + pageNum + ", totalPage=" + totalPage + ", pageSize=" + pageSize + ", startIndex="
				+ startIndex + ", total=" + total + ", list=" + list + ", params=" + params + "]";
	}
	
}
